package com.tmanager.web.services;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;
import com.tmanager.persistence.dao.ActivityDAO;
import com.tmanager.persistence.dao.UserDAO;
import com.tmanager.persistence.entity.Activity;
import com.tmanager.persistence.entity.User;
import com.tmanager.persistence.tx.Transactional;

public class UserActivityService {
	private static final Logger log = LoggerFactory.getLogger(UserActivityService.class);
	@Inject
	private ActivityDAO activityDAO;
	@Inject
	private UserDAO userDAO;
	
	@Transactional
	public String getActivity(User user,long timeStart,long timeEnd){
		user = userDAO.getUserByEmail("admin@test.com");
		List<Activity> activities = activityDAO.getAllByDates(user.getId(), timeStart, timeEnd);
		JSONArray array = new JSONArray();
		for(Activity activity : activities){
			try {
				array.put(activity.toJSON());
			} catch (JSONException e) {
				log.error(e.getMessage(),e);
			}
		}
		return array.toString();
	}
}
